<?php
declare (strict_types = 1);

namespace app\middleware;
use app\api\server\Token as TokenServer;

class CheckToken
{
    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {
        //第一步先取token
        $name =  $request->post('name');
        // var_dump($name);die;
        $token = $request->header('Authorization');
        // var_dump($token);die;
        //jwt进行校验token
        $res = (new TokenServer())->chekToken($token);

        if ($res['code'] != 1 ){
            return json(['error_code'=>999,'msg'=>$res['msg'],'data'=>''],400);
        }
        $request->uid = $res['data']->uid;
        return $next($request);
    }
}
